package com.lboyang.provider.registry.zk;


import com.lboyang.provider.registry.ServiceRegistry;
import com.lboyang.provider.registry.zk.util.CuratorUtils;
import org.apache.curator.framework.CuratorFramework;

import java.net.InetSocketAddress;

/**
 * @Description
 *      基于 ZooKeeper 服务注册
 * @Date 2021/9/11 23:19
 * @author: A.iguodala
 */
public class ZkServiceRegistryImpl implements ServiceRegistry {

    /**
     * 注册服务到 ZooKeeper
     * @param rpcServiceName 对应的服务名
     * @param inetSocketAddress 服务地址
     */
    @Override
    public void registerService(String rpcServiceName, InetSocketAddress inetSocketAddress) {
        String servicePath = CuratorUtils.ZK_REGISTER_ROOT_PATH + "/" + rpcServiceName + inetSocketAddress.toString();
        CuratorFramework zkClient = CuratorUtils.getZkClient();
        CuratorUtils.createPersistentNode(zkClient, servicePath);
    }
}
